home *** CD-ROM | disk | FTP | other *** search
/ Power Tools for Macintosh / Power Tools for Macintosh (SoftBit)(1992).iso / Applications / Alpha 4.01 / ACMDS / dir.c < prev    next >
C/C++ Source or Header  |  1990-01-27  |  3KB  |  114 lines

  1. #include    <MacHeaders>
  2. #define        NULL        0L
  3.  
  4. static OSErr    err;
  5. static int        gHaveAUX = FALSE;
  6.  
  7.  
  8. /** PathNameFromDirID *********************************************************/
  9.  
  10. char *
  11. PathNameFromDirID(DirID, vRefNum, s)
  12. long        DirID;
  13. short        vRefNum;
  14. char        *s;
  15. {
  16.     CInfoPBRec    block;
  17.     Str255        directoryName;
  18.  
  19. /*    *s = 0;                Don't want to null because file name is there */
  20.     block.dirInfo.ioNamePtr = directoryName;
  21.     block.dirInfo.ioDrParID = DirID;
  22.  
  23.     do {
  24.         block.dirInfo.ioVRefNum = vRefNum;
  25.         block.dirInfo.ioFDirIndex = -1;
  26.         block.dirInfo.ioDrDirID = block.dirInfo.ioDrParID;
  27.  
  28.         if (err = PBGetCatInfo(&block,false))
  29.         {
  30.             SysBeep(1);
  31.             return;
  32.         }
  33.         
  34.         if (gHaveAUX) {
  35.             if (directoryName[1] != '/')
  36.                 /* If this isn't root (i.e. '/'), append a slash ('/') */
  37.                 pStrcat(directoryName,"\p/");
  38.         } else 
  39.             /* Append a Macintosh style colon (':') */
  40.             pStrcat(directoryName,"\p:");
  41.         pStrcat(directoryName,s);
  42.         pStrcpy(s,directoryName);
  43.     } while (block.dirInfo.ioDrDirID != fsRtDirID);
  44.  
  45.     return(s);
  46. }
  47.  
  48.  
  49. /** PathNameFromWD ************************************************************/
  50.  
  51. char *
  52. PathNameFromWD(vRefNum,s)
  53. long    vRefNum;
  54. char    *s;
  55. {
  56.  
  57.     WDPBRec    myBlock;
  58.  
  59.     /*
  60.     /* PBGetWDInfo has a bug under A/UX 1.1.  If vRefNum is a real vRefNum
  61.     /* and not a wdRefNum, then it returns garbage.  Since A/UX has only 1
  62.     /* volume (in the Macintosh sense) and only 1 root directory, this can
  63.     /* occur only when a file has been selected in the root directory (/).
  64.     /* So we look for this and hard code the DirID and vRefNum. */
  65.  
  66.     if (gHaveAUX && (vRefNum == -1))
  67.         return(PathNameFromDirID(2,-1,s));
  68.  
  69.     myBlock.ioNamePtr = NULL;
  70.     myBlock.ioVRefNum = vRefNum;
  71.     myBlock.ioWDIndex = 0;
  72.     myBlock.ioWDProcID = 0;
  73.  
  74.     /* Change the Working Directory number in vRefnum into a real vRefnum */
  75.     /* and DirID. The real vRefnum is returned in ioVRefnum, and the real */
  76.     /* DirID is returned in ioWDDirID. */
  77.  
  78.     if (err = PBGetWDInfo(&myBlock,false)) 
  79.     {
  80.         SysBeep(1); return;
  81.     }
  82.  
  83.     return(PathNameFromDirID(myBlock.ioWDDirID,myBlock.ioWDVRefNum,s));
  84. };
  85.  
  86.  
  87. condensePathname(path)
  88. char    *path;
  89. {
  90.     char        str[256], *ptr, *ptr2;
  91.     extern int    condensed;
  92.     
  93.     if (!condensed) return;
  94.     
  95.     ptoc(path);
  96.     for (ptr = path; *ptr && (*ptr != ':'); ptr++);
  97.     strncpy(str,path, (int)(ptr - path));
  98.     str[ptr - path] = 0;
  99.     for (ptr = path + strlen(path); (*ptr != ':') && (ptr > path); ptr--);
  100.     ptr2 = ptr--;
  101.     while ((*ptr != ':') && (ptr > path))  ptr--;
  102.     if (ptr < path)
  103.     {
  104.         strcpy(str,ptr2);
  105.     }
  106.     else
  107.     {
  108.         strcat(str,":...");
  109.         strcat(str,ptr);
  110.     }
  111.     strcpy(path,str);
  112.     ctop(path);
  113. }
  114.